package com.atguigu.springcloud.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author lizhilong
 * @create 2020/4/19 21:37
 * @desc
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommonResult<T> {

    private String code;

    private String message;

    private T data;

    public CommonResult(String code, String message) {
        this(code, message, null);
    }

    public static <T> CommonResult<T> success(T data) {
        CommonResult<T> cr = new CommonResult<T>();
        cr.setCode("200");
        cr.setMessage("成功");
        cr.setData(data);
        return cr;
    }

    public static <T> CommonResult<T> failure(String message) {
        CommonResult<T> cr = new CommonResult<T>();
        cr.setCode("500");
        cr.setMessage(message);
        cr.setData(null);
        return cr;
    }


    public static <T> CommonResult<T> failure(String errorCode,String message) {
        CommonResult<T> cr = new CommonResult<T>();
        cr.setCode(errorCode);
        cr.setMessage(message);
        cr.setData(null);
        return cr;
    }
}
